var modal = document.getElementById("myModal");
// 获取按钮，点击按钮打开弹窗
var btn = document.getElementById("dialog");

// 获取 <span> 元素，点击 <span> (x)，关闭弹窗
var span = document.getElementsByClassName("close")[0];

// 当用户点击按钮，打开弹窗
btn.onclick = function() {
    modal.style.display = "block";
}

// 当用户点击 <span> (x)，关闭弹窗
span.onclick = function() {
    modal.style.display = "none";
}

// 当用户点击弹窗外部时，关闭弹窗
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}